package com.reebake.ideal.user.controller;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.reebake.ideal.mybatis.core.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.reebake.ideal.user.entity.UserInfo;
import com.reebake.ideal.user.service.UserInfoService;
import com.reebake.ideal.user.vo.UserInfoQueryParamVO;
import com.reebake.ideal.user.vo.UserInfoVO;

 /**
 * 用户信息控制层
 */
@Tag(name = "用户信息对象功能接口")
@RestController
@RequestMapping("/user/info")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;
    
    /** 
     * 分页查询
     *
     * @param queryParam 查询参数
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("page")
    public PageResult<UserInfoVO> page(@RequestBody UserInfoQueryParamVO queryParam) {
        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getPhoneNumber()), UserInfo::getPhoneNumber, queryParam.getPhoneNumber());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getNickname()), UserInfo::getNickname, queryParam.getNickname());
        
        queryParam = userInfoService.page(queryParam, queryWrapper);
        
        return queryParam.to(UserInfoVO.class);
    }
    
    /** 
     * 保存或更新数据
     *
     * @param userInfo 实例对象
     */
    @Operation(summary = "保存数据")
    @PostMapping("save")
    public void save(@RequestBody UserInfoVO userInfo) {
        userInfoService.saveOrUpdate(BeanUtil.copyProperties(userInfo, UserInfo.class));
    }
    
    /** 
     * 通过主键批量删除
     *
     * @param userIds 主键
     */
    @Operation(summary = "通过主键删除多条数据")
    @PostMapping("remove-by-ids")
    public void removeByIds(@RequestBody List<String> userIds) {
        userInfoService.removeByIds(userIds);
    }
}